home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0018_PRIMES2.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  1KB  |  52 lines

  1. {
  2. BRIAN PAPE
  3.  
  4. >   Go to the library and look up the Sieve of Eratosthenes; it's a very
  5. >interesting and easy method For "finding" prime numbers in a certain
  6. >range - and kinda fun to Program in Pascal, I might add...
  7. }
  8.  
  9. Program aristophenses_net;
  10. {
  11.  LCCC Computer Bowl November 1992 Team members:
  12.  Brian Pape, Mike Lazar, Brian Grammer, Kristy Reed - total time: 5:31
  13. }
  14.  
  15. Const
  16.   size = 5000;
  17. Var
  18.   b     : Array [1..size] of Boolean;
  19.   i, j,
  20.   count : Integer;
  21.  
  22. begin
  23.   count := 0;
  24.   Writeln;
  25.   Write('WORKING: ', ' ' : 6, '/', size : 6);
  26.   For i := 1 to 13 do
  27.     Write(#8);
  28.   fillChar(b, sizeof(b), 1);
  29.  
  30.   For i := 2 to size do
  31.     if b[i] then
  32.     begin
  33.       Write(i : 6, #8#8#8#8#8#8);
  34.       For j := i + 1 to size do
  35.         if j mod i = 0 then
  36.           b[j] := False;
  37.     end;  { For }
  38.  
  39.   Writeln;
  40.  
  41.   For i := 1 to size do
  42.     if b[i] then
  43.     begin
  44.       Write(i : 8);
  45.       inc(count);
  46.     end;
  47.  
  48.   Writeln;
  49.   Write('The number of primes from 1 to ', size, ' is ', count, '.');
  50. end.
  51.  
  52.